<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" >
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>


<form class="layui-form" onsubmit="return false">

<div class="layui-form-item">
    <label class="layui-form-label">组名</label>
    <div class="layui-input-inline">
      <input type="text" id="agname" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
      <label class="layui-form-label">排序</label>
      <div class="layui-input-inline">
        <input type="text" id="sort" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-inline">
          <input type="text" id="descript" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
          <label class="layui-form-label">组图标</label>
          <div class="layui-input-inline">
            <input type="text" id="icon" lay-verify="identity" placeholder="" autocomplete="off" class="layui-input">
          </div>
        </div>



     <div class="layui-form-item">
         <label class="layui-form-label">所属分类</label>
         <div class="layui-input-block">
           <input type="text" name="areas" id="a" style="display: none;"  />
         </div>
       </div>

      <button class="layui-btn"  id="verivy" style="margin-left: 100px">确认</button>
      <button class="layui-btn layui-btn-primary" type="reset">重置</button>
</form>


<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" ></script>
<script src="../../lib/layui-v2.5.5/layui.js" ></script>



</body>

<script type="text/javascript">

  layui.config({
    base: '../../js/ext/'
  }).extend({
    cascader: 'cascader/cascader'
  }).use(['jquery', 'cascader','form'], function () {
    var $ = layui.jquery, cascader = layui.cascader;
	var areaTree =getdata();

	 var form = layui.form;
	function getdata(){
            var datac=[];
            $.ajax({
                url:'/product/pmscategory/list/tree',
                type:'get',
                async:false,
                success:function(databack){
                  datac=databack
                }
            });
            return datac.data;
        }

    cascader.render({
      elem: $('input[name=areas]')[0],
      multiple: false,
      showAllLevels: true,
      props: {
        label: 'name',
        value: 'catId',
        children: 'children'
      },
      options: areaTree

    });

	$("#verivy").on('click',function() {
	   var cid=$("input[name=areas]").val();
       var a = cid.split(',');
	        var agname=$("#agname").val(),
       	     descript=$("#descript").val(),
       	     icon=$("#icon").val(),
       	     sort=$("#sort").val();
	    $.ajax({

                url:"/product/pmsspu/add",
	            type:"get",
	            data:{
	                agname:agname,
	                sort:sort,
	                catelogid:a[a.length-1],
	                icon:icon,
	                descript:descript
	            },
	            dataType:"json",
	            success:function(data) {
	              if (data==0) {
                  							layer.msg('修改失败！',{icon:5,offset:"auto",time:2000});//提示框
                  						}else  {
                  							layer.msg('修改成功！',{icon:6,offset:"auto",time:2000});//提示框
                  						}
                  						setTimeout(function(){
                  							var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
                  							parent.layer.close(index);//关闭弹出层
                  							parent.layui.table.reload("spu"); //重新加载页面表格
                  						}, 2100);
	            }
	    })

	});

  });
  </script>

</html>